﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace JmShared
{
    /// <summary>
    /// Messages and commands clients can send to the server to be processed or relayed.
    /// </summary>

    public class ChatMessage
    {
        #region Fields

        private string _message;

        #endregion

        #region Properties

        public MessageType MessageType { get; set; }

        /// <summary>
        /// Group ID for chat group,or usename for PM
        /// </summary>

        public string RecipientID { get; set; }

        public string SenderDeviceID { get; set; }

        public string SenderUsername { get; set; }

        public string Message
        {
            get { return this._message ?? String.Empty; }
            set { this._message = value; }
        }

        public DateTime? MessageRelayTime { get; set; }


        public int? MessageID { get; set; }

        [Obsolete("Used for backwards compability. Functionality replaced with MessageQueue class.")]
        public MessageQueueInfo MessageQueueInfo { get; set; }

        //
        //public UserInfo SenderInfo { get; set; }
        /// <summary>
        /// The senders Username and DeviceID combined: e.g MyUsername@Example.com#324asdg3g3
        /// </summary>
        public string SenderID
        {
            get
            {
                return this.SenderUsername + "#" + this.SenderDeviceID;
            }
        }

        #endregion

        #region Constructor
        public ChatMessage(string senderDeviceID, string senderUsername, MessageType mt, string message, string recipientID)
        {
            this.SenderDeviceID = senderDeviceID;
            this.SenderUsername = senderUsername;
            this.RecipientID = recipientID;
            this.MessageType = mt;
            this.Message = message;
        }
        public ChatMessage(string senderDeviceID, string senderUsername, MessageType mt, string message)
        {
            this.SenderDeviceID = senderDeviceID;
            this.SenderUsername = senderUsername;
            this.MessageType = mt;
            this.Message = message;
        }
        public ChatMessage(string senderDeviceID, string senderUsername, MessageType mt)
        {
            this.SenderDeviceID = senderDeviceID;
            this.SenderUsername = senderUsername;
            this.MessageType = mt;

        }
        public ChatMessage(UserInfo sender, MessageType mt, string message, string recipientID)
        {
            this.SenderDeviceID = sender.ID;
            this.SenderUsername = sender.UserName;
            this.MessageType = mt;
            this.Message = message;
            this.RecipientID = recipientID;
        }
        public ChatMessage(UserInfo sender, MessageType mt, string message)
        {
            this.SenderDeviceID = sender.ID;
            this.SenderUsername = sender.UserName;
            this.MessageType = mt;
            this.Message = message;
        }
        public ChatMessage(UserInfo sender, MessageType mt)
        {
            this.SenderDeviceID = sender.ID;
            this.SenderUsername = sender.UserName;
            this.MessageType = mt;
        }

        private ChatMessage() { }
        #endregion
        #region methods
        public override string ToString()
        {
            return Message;
        }
        #endregion
    }
}


